package com.mk.wardsystemserver.controller;


import com.mk.wardsystemserver.pojo.*;
import com.mk.wardsystemserver.service.IPatientService;
import com.mk.wardsystemserver.service.IRoomService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhoubin
 * @since 2022-03-24
 */
@RestController
@RequestMapping("/patient")
public class PatientController {
    @Autowired
    private IPatientService patientService;
    @Autowired
    private IRoomService roomService;
    @ApiOperation(value = "获取所有病人 (分页)")
    @GetMapping("/")
    public RespPageBean getEmployee(@RequestParam(defaultValue = "1") Integer pageCurrent,
                                    @RequestParam(defaultValue = "10") Integer pageSize,
                                    Patient patient) {
        return patientService.getPatientByPage(pageCurrent, pageSize, patient);
    }

    @ApiOperation(value="添加病人信息")
    @PostMapping("/")
    public RespBean addPatient(@RequestBody Patient patient) {
        return patientService.addPatient(patient);
    }

    @ApiOperation(value = "更新病人信息")
    @PutMapping("/")
    public RespBean updatePatient(@RequestBody Patient patient) {
        if (patientService.updateById(patient)) {
            return RespBean.success("更新成功！");
        }
        return RespBean.error("更新失败");
    }
    @ApiOperation(value = "删除病人信息")
    @DeleteMapping("/{id}")
    public RespBean deletePatient(@PathVariable Integer id){
        if(patientService.removeById(id)){
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");
    }
    @ApiOperation(value = "批量删除")
    @DeleteMapping("/")
    public RespBean deletePositionsByIds(Integer[] ids){
        if (patientService.removeByIds(Arrays.asList(ids))){
            return RespBean.success("批量删除成功!");
        }
        return RespBean.error("批量删除失败！");
    }

    @ApiOperation(value = "获取所有病房类型")
    @GetMapping("/wardRoomType")
    public List<Room> getAllRoom() {
        return roomService.getRoomType();
    }

    @ApiOperation(value = "获取费用明细")
    @GetMapping("/payDetails")
    public List<Patient> getDetails(){
        return patientService.getPayDetails();
    }

    @ApiOperation(value="治疗信息查询")
    @GetMapping("/treatInfo")
    public RespPageBean getTreatInfo(@RequestParam(defaultValue = "1") Integer pageCurrent,
                                     @RequestParam(defaultValue = "10") Integer pageSize,
                                     Patient patient){
        return patientService.getInfo(pageCurrent,pageSize,patient);
    }

    @ApiOperation(value = "更新结算信息")
    @PutMapping("/payInfo")
    public RespBean updatePayInfo(@RequestBody Patient patient){
        if (patientService.updateById(patient)){
            return RespBean.success("更新成功！");
        }
        return RespBean.error("更新失败！");
    }
}
